package dao;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

@Entity
@NamedQueries({
	@NamedQuery(name="searchWaitingCode",query=" from Waiting w where w.OID = :code"),
	@NamedQuery(name="searchWaitingDate",query=" from Waiting w where w.dhWaiting between :dateS and :dateE order by dhWaiting ASC"),
	@NamedQuery(name="searchWaiting",query=" from Waiting w where w.dhWaiting = :date")
})
public class Waiting {
	@Id
	@GeneratedValue
	private int OID;
	private String deService;

	private Date dhWaiting;

	@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
	private Customer customer;

	public int getOID() {
		return OID;
	}

	public void setOID(int oID) {
		OID = oID;
	}

	public String getDeService() {
		return deService;
	}

	public void setDeService(String deService) {
		this.deService = deService;
	}

	public Date getDhWaiting() {
		return dhWaiting;
	}

	public void setDhWaiting(Date dhWaiting) {
		if(dhWaiting != null){
			this.dhWaiting = new Date(dhWaiting.getTime());
		}else{
			this.dhWaiting = dhWaiting;
		}
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	public String getWaiting(){
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		return sdf.format(dhWaiting);
	}
}
